﻿-- 创建库
CREATE DATABASE Blogs COLLATE Chinese_PRC_CI_AS;
GO

-- 创建表
USE Blogs
GO

DROP TABLE IF EXISTS Article;
CREATE TABLE Article
(
    Id        INT IDENTITY(1,1) NOT NULL,
    Type      INT      NOT NULL DEFAULT 1,
    Title     NVARCHAR (100) NOT NULL,
    Content   NVARCHAR ( MAX),
    AuthorId  INT      NOT NULL,
    Status    INT      NOT NULL DEFAULT 1,
    CreatedAt DATETIME NOT NULL default CURRENT_TIMESTAMP,
    CONSTRAINT PK_Article PRIMARY KEY (Id)
);

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文章表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文章ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'Id';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文章类型(1:技术;2:财经;3:散文)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'Type';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文章标题' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'Title';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'文章内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'Content';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'作者ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'AuthorId';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'状态(1:正常;2:草稿:3:删除)',@level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'Status';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Article', @level2type=N'COLUMN',@level2name=N'CreatedAt';

INSERT INTO Article (Type, Title, Content, AuthorId, Status, CreatedAt)
VALUES (1, '技术文章1', '这是一篇技术文章的内容', 1001, 1, '2022-05-01 10:00:00'),
       (2, '财经文章1', '这是一篇财经文章的内容', 1002, 2, '2022-06-01 11:00:00'),
       (1, '技术文章2', '这是另一篇技术文章的内容', 1003, 3, '2022-07-01 12:00:00'),
       (3, '优美散文1', '这是一篇优美散文内容', 1003, 1, '2022-08-01 12:00:00');